<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 1.创建svg元素
    const XMLNS = "http://www.w3.org/2000/svg"
    const svgEl = document.createElementNS(XMLNS, "svg")
    const rectEl = document.createElementNS(XMLNS, 'rect')

    // 2.添加属性
    svgEl.setAttributeNS(null, 'version', '1.0')
    svgEl.setAttributeNS(null, 'width', '100')
    svgEl.setAttributeNS(null, 'height', '100')
    rectEl.setAttributeNS(null, 'width', '50')
    rectEl.setAttributeNS(null, 'height', '50')

    // 3.页面 body 中插入元素
    svgEl.appendChild(rectEl)
    document.body.appendChild(svgEl)
  </script>
</body>
</html>